package cn.example.demo.common.secure.datascope;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 数据范围类型
 *
 * @author Lizuxian
 * @create 2022/4/17 15:21
 */
@Getter
@AllArgsConstructor
public enum DataScopeType {
    ALL("DS_01", "全部数据"),
    ORG_WITH_CHILD("DS_02", "本组织及下级数据"),
    ORG("DS_03", "本组织数据"),
    DEFINE("DS_04", "指定组织数据"),
    SELF("DS_05", "仅本人数据");

    private final String code;
    private final String name;

    /**
     * 根据code获取枚举
     */
    public static DataScopeType codeToEnum(String code) {
        if (null != code) {
            for (DataScopeType e : DataScopeType.values()) {
                if (e.getCode().equals(code)) {
                    return e;
                }
            }
        }
        return null;
    }

    /**
     * 编码转化成中文含义
     *
     * @author liuhanqing
     * @date 2021/1/15 13:36
     */
    public static String codeToName(String code) {
        if (null != code) {
            for (DataScopeType e : DataScopeType.values()) {
                if (e.getCode().equals(code)) {
                    return e.getName();
                }
            }
        }
        return "未知";
    }
}
